<!DOCTYPE html>
<html lang="en" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>新冠疫苗接种登记</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/css/custom.form.css">
    <style>
        .classInput {
            width: 350px;
            margin-top: 20px;
            border-radius: 10px;
        }

        #dukabuttion {
            position: absolute;
            left: 360px;
            top: 0px;
            border-radius: 20px;
        }

    </style>
</head>
<body>
<div class="panel panel-default operation">
    <div class="layui-field-box">
        <div class="layui-card-body">
            <div class="layui-container">
                <form class="layui-form " action="" lay-filter="info" style="width: 100%">

                    <div class="layui-row">
                        <div class="layui-col-md4">&emsp;</div>
                        <div class="layui-col-md4" style="font-size:19px;text-align: center;">长兴县新冠疫苗接种辖区登记</div>
                        <div class="layui-col-md4">&emsp;</div>
                    </div>
                    <hr class="layui-bg-orange">
                    <div class="layui-row">
                        <!-- <div class="layui-col-md2">&lt;!&ndash;左二&ndash;&gt;</div>-->
                        <div class="layui-col-md12">
                            <div class="layui-form-item">
                                <label class="layui-form-label"><span style="color: red">*</span>辖区选择</label>
                                <div class="layui-input-block">
                                    <!--&emsp;-->
                                    <input type="radio" class="xzqhClass" lay-filter="erweima" name="xzqh"
                                           value="330522003" id="330522003"
                                           lay-verify="otherReq" title="太湖街道">
                                    <input type="radio" class="xzqhClass" lay-filter="erweima" name="xzqh"
                                           value="330522100" id="330522100"
                                           lay-verify="otherReq" title="雉城街道">
                                    <input type="radio" class="xzqhClass" lay-filter="erweima" name="xzqh"
                                           value="330522101" id="330522101"
                                           lay-verify="otherReq" title="洪桥镇">
                                    <input type="radio" class="xzqhClass" lay-filter="erweima" name="xzqh"
                                           value="330522102" id="330522102"
                                           lay-verify="otherReq" title="李家巷镇">
                                    <input type="radio" class="xzqhClass" lay-filter="erweima" name="xzqh"
                                           value="330522103" id="330522103"
                                           lay-verify="otherReq" title="夹浦镇">
                                    <input type="radio" class="xzqhClass" lay-filter="erweima" name="xzqh"
                                           value="330522104" id="330522104"
                                           lay-verify="otherReq" title="林城镇">
                                    <input type="radio" class="xzqhClass" lay-filter="erweima" name="xzqh"
                                           value="330522105" id="330522105"
                                           lay-verify="otherReq" title="泗安镇">
                                    <input type="radio" class="xzqhClass" lay-filter="erweima" name="xzqh"
                                           value="330522106" id="330522106"
                                           lay-verify="otherReq" title="虹星桥镇">
                                    <input type="radio" class="xzqhClass" lay-filter="erweima" name="xzqh"
                                           value="330522107" id="330522107"
                                           lay-verify="otherReq" title="和平镇">
                                    <input type="radio" class="xzqhClass" lay-filter="erweima" name="xzqh"
                                           value="330522108" id="330522108"
                                           lay-verify="otherReq" title="小浦镇">
                                    <input type="radio" class="xzqhClass" lay-filter="erweima" name="xzqh"
                                           value="330522109" id="330522109"
                                           lay-verify="otherReq" title="煤山镇">
                                    <input type="radio" class="xzqhClass" lay-filter="erweima" name="xzqh"
                                           value="330522200" id="330522200"
                                           lay-verify="otherReq" title="水口乡">
                                    <input type="radio" class="xzqhClass" lay-filter="erweima" name="xzqh"
                                           value="330522202" id="330522202"
                                           lay-verify="otherReq" title="吕山乡">
                                    <input type="radio" class="xzqhClass" lay-filter="erweima" name="xzqh"
                                           value="330522206" id="330522206"
                                           lay-verify="otherReq" title="画溪街道">
                                    <input type="radio" class="xzqhClass" lay-filter="erweima" name="xzqh"
                                           value="330522401" id="330522401"
                                           lay-verify="otherReq" title="太湖图影">
                                    <input type="radio" class="xzqhClass" lay-filter="erweima" name="xzqh"
                                           value="330522802" id="330522802"
                                           lay-verify="otherReq" title="龙山街道">
                                </div>
                            </div>
                        </div>
                        <!--                    <div class="layui-col-md2">&lt;!&ndash;右二&ndash;&gt;</div>-->
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red">*</span>机关部门</label>
                        <div class="layui-input-inline">
                            <select name="department" lay-filter="department" id="departmentId" lay-search>
                                <option value="">请选择</option>
                                <option value="330522900">县委办(xwb)</option>
                                <option value="330522901">人大办(rdb)</option>
                                <option value="330522902">政协办(zxb)</option>
                                <option value="330522903">纪 委(jw)</option>
                                <option value="330522904">组织部(zzb)</option>
                                <option value="330522905">宣传部(xcb)</option>
                                <option value="330522906">政法委(zfw)</option>
                                <option value="330522907">信访局(xfj)</option>
                                <option value="330522908">档案馆(dag)</option>
                                <option value="330522909">编 办(bb)</option>
                                <option value="330522910">团县委(txw)</option>
                                <option value="330522911">妇 联(fl)</option>
                                <option value="330522912">总工会(zgh)</option>
                                <option value="330522913">科 协(kx)</option>
                                <option value="330522914">工商联(gsl)</option>
                                <option value="330522915">发改局(fgj)</option>
                                <option value="330522916">金融办(jrb)</option>
                                <option value="330522917">审计局(sjj)</option>
                                <option value="330522918">水利局(slj)</option>
                                <option value="330522919">医疗保障局(ylbzj)</option>
                                <option value="330522920">退役军人事务局(tyjrswj)</option>
                                <option value="330522921">政务办(zwb)</option>
                                <option value="330522922">机关事务中心(jgswzx)</option>
                                <option value="330522923">气象局(qxj)</option>
                                <option value="330522924">生态环境局长兴分局(sthjj)</option>
                                <option value="330522925">公积金中心(gjjzx)</option>
                                <option value="330522926">国家大学科技园(gjdxkjy)</option>
                                <option value="330522927">供销社(gxs)</option>
                                <option value="330522928">经信局(jxj)</option>
                                <option value="330522929">农业农村局(nyncj)</option>
                                <option value="330522930">应急管理局(yjglj)</option>
                                <option value="330522931">财政局(czj)</option>
                                <option value="330522932">社会矛盾纠纷调处化解中心(shmdjftchjzx)</option>
                                <option value="330522933">金融控股集团(jrkgjt)</option>
                                <option value="330522934">文联(wl)</option>
                                <option value="330522935">税务局(swj)</option>
                                <option value="330522936">交投集团(jtjt)</option>
                                <option value="330522937">自然资源局(zrzyj)</option>
                                <option value="330522938">城投集团(ctjt)</option>
                                <option value="330522939">市场监管局(scjgj)</option>
                                <option value="330522940">民政局(mzj)</option>
                                <option value="330522941">综合执法局(zhzfj)</option>
                                <option value="330522942">传媒集团(cmjt)</option>
                                <option value="330522943">公安局(gaj)</option>
                                <option value="330522944">卫健局(wjj)</option>
                                <option value="330522945">村镇银行(czyh)</option>
                                <option value="330522946">教育局(jyj)</option>
                                <option value="330522947">县府办(xfb)</option>
                                <option value="330522948">烟草局(ycj)</option>
                                <option value="330522949">大数据局(dsjj)</option>
                                <option value="330522950">建设局(jsj)</option>
                                <option value="330522951">科技局(kjj)</option>
                                <option value="330522952">统战部(tzb)</option>
                                <option value="330522953">党 校(dx)</option>
                                <option value="330522954">残 联(cl)</option>
                                <option value="330522955">法 院(fy)</option>
                                <option value="330522956">检察院(jcy)</option>
                                <option value="330522957">统计局(tjj)</option>
                                <option value="330522958">人社局(rsj)</option>
                                <option value="330522959">邮政管理局(yzglj)</option>
                                <option value="330522960">红十字会(hszh)</option>
                                <option value="330522961">司法局(sfj)</option>
                                <option value="330522962">商务局(swj)</option>
                                <option value="330522963">交通运输局(jtysj)</option>
                                <option value="330522964">文广旅体局(wgltj)</option>
                                <option value="330522501">长兴县人民医院(xrmyy)</option>
                                <option value="330522965">电信公司(dxgs)</option>
                                <option value="330522966">联通公司(ltgs)</option>
                                <option value="330522967">人民银行(rmyh)</option>
                                <option value="330522968">文旅集团(wljt)</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-row">
                        <div class="layui-col-md12">
                            <div class="layui-form-item">
                                <label class="layui-form-label"><span style="color: red">*</span>针次</label>
                                <div class="layui-input-block">
                                    <input type="radio" class="zcClass" name="stitches" value="01" id="01"
                                           lay-verify="zcReq" title="第一针">
                                    <input type="radio" class="zcClass" name="stitches" value="02" id="02"
                                           lay-verify="zcReq" title="第二针">
                                    <input type="radio" class="zcClass" name="stitches" value="03" id="03"
                                           lay-verify="zcReq" title="第三针">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red">*</span>身份证号</label>
                        <div class="layui-input-block">
                            <input type="identity" id="certNumber" name="identity" placeholder="请输入身份证号"
                                   autocomplete="off"
                                   lay-verify="required|identity" lay-reqtext="请输入接种人身份证号"
                                   class="layui-input classInput">
                            <!--                                    <input type="button" value="读卡" onclick="readCert()">-->
                            <button type="button" class="layui-btn" onclick="readCert()" id="dukabuttion" style="float: left ;">读卡</button>
                            <button type="button" class="layui-btn  " id="search"  style="background-color: #2A569B;border-radius: 20px; position: absolute;top: 0px;left: 430px;">查询</button>
                        </div>
                    </div>
                    <div class="layui-row">
                        <!--                    <div class="layui-col-md2">&lt;!&ndash;左二&ndash;&gt;</div>-->
                        <div class="layui-col-md6">
                            <div class="layui-form-item">
                                <label class="layui-form-label">姓名</label>
                                <div class="layui-input-block">
                                    <!--onFocus="readCert()"-->
                                    <input type="name" id="partyName" name="name" placeholder="请输入姓名"
                                           autocomplete="off" class="layui-input classInput">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">性别</label>
                                <div class="layui-input-block">
                                    <input type="radio" class="sexClass" name="sex" id="sex1" value="1" title="男">
                                    <input type="radio" class="sexClass" name="sex" id="sex2" value="2" title="女">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">出生日期</label>
                                <div class="layui-input-block">
                                    <input type="birthday" id="bornDay" name="birthday" placeholder="请输入出生日期"
                                           autocomplete="off" class="layui-input classInput"
                                    >
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">户籍地址</label>
                                <div class="layui-input-block">
                                    <input type="address" id="certAddress" name="address" placeholder="请输入家庭地址"
                                           autocomplete="off" class="layui-input classInput">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">登记人</label>
                                <div class="layui-input-block">
                                    <input type="registrant" id="registrant" name="registrant" readonly="readonly"
                                           autocomplete="off" class="layui-input classInput"/>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <div class="layui-form-item">
                                <label class="layui-form-label"></label>
                                <div class="layui-input-block">
                                    <!--<input type="phone" name="phone" placeholder="请输入头像图片" autocomplete="off" class="layui-input">-->
                                    <img id="HeadPic" style="height: 126px; width: 102px"
                                         src=""/>
                                    <input type="hidden" name="phone" id="phone" value=""/>
                                    <input type="hidden" name="township" id="township" value=""/>
                                    <!--<img id="PhotoDisplay" style="width:341px; height:443px;"/>-->
                                </div>
                            </div>
                        </div>
                        <!--                    <div class="layui-col-md2">&lt;!&ndash;右二&ndash;&gt;</div>-->
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">保存</button>
                            <button type="button" class="layui-btn layui-btn-primary" onclick="returnClear()">返回
                            </button>
                        </div>
                    </div>
                </form>
                <hr class="layui-bg-orange">
            </div>
        </div>
    </div>
    <object id="CertCtl" type="application/cert-reader" width="0" height="0">
        <object classid="clsid:30516390-004F-40B9-9FC6-C9096B59262E" id="CertCtl" width="0" height="0">
            <object ID="CertCtl" classid="30516390-004F-40B9-9FC6-C9096B59262E" TYPE="application/cert-reader" width=0
                    height=0>
                <!--<p style="color:#FF0000;">控件不可用，可能未正确安装控件及驱动，或者控件未启用。</p>-->
            </object>
        </object>
    </object>
</div>
</body>
</html>
<script src="/layui/layui.all.js"></script>
<script src="/js/core.util.js"></script>
<script>
    //获取token
    var token = CoreUtil.getData("access_token");
    //地址栏转义token中的#号
    var tableIns1;
    var table = layui.table;
    var form = layui.form;
    var layer = layui.layer;
    var $ = jQuery = layui.jquery;
    var laydate = layui.laydate;
    layui.use(['table', 'layer', 'laydate'], function () {
        laydate.render({
            elem: '#bornDay' //指定元素
            , type: 'date'
            , trigger: 'click',
            format: 'yyyyMMdd'
        });
        $("#search").on('click', function(){
            var identity = $("#certNumber").val();
            var exportParams = {
                identity : identity
            };
            CoreUtil.sendPost("/vaccination/pinfobyidcard", exportParams, function (res) {
                if(res.data.length>0){

                    var radioxzqh = $(".xzqhClass");
                    var departmentId =  $("#departmentId option");
                    var radiozc = $(".zcClass");
                    var radiosex = $(".sexClass");
                    var partyName = $("#partyName");
                    var sex1 =  $("#sex1");
                    var sex2 =  $("#sex2");
                    var bornday = $("#bornDay");
                    var certAddress = $("#certAddress");

                    var xzqh = res.data[0]["xzqh"];
                    var township = res.data[0]["township"];
                    var stitches = res.data[0]["stitches"];
                    var name = res.data[0]["name"];
                    var sex = res.data[0]["sex"];
                    var birthday = res.data[0]["birthday"];
                    var address = res.data[0]["address"];

                    if(xzqh != ""){
                        radioxzqh.each(function (index, el) {
                            if(xzqh==radioxzqh[index].value){
                                $(':radio[name="xzqh"]').eq(index).prop("checked",true);
                                form.render('radio');
                                document.getElementById("township").value = township;
                            }
                        });
                    }

                    if(xzqh != ""){
                        $("#departmentId").val(xzqh);
                        layui.form.render("select");
                    }

                    if(stitches != ""){
                        radiozc.each(function (index, el) {
                            if(stitches==radiozc[index].id){
                                $(':radio[name="stitches"]').eq(index+1).prop("checked",true);
                                form.render('radio');
                            }
                        });
                    }

                    partyName.val(name);
                    // var time1 = new Date(birthday);
                    // time1.setTime(time1.getTime());
                   if(birthday != ""){
                       console.log(birthday);
                       var time1 = birthday.substring(0,4)+birthday.substring(5,7)+birthday.substring(8,10);
                       bornday.val( time1);
                   }
                    radiosex.each(function (index, el) {
                        if(sex==radiosex[index].value){
                            radiosex[index].checked = true;
                            form.render('radio');
                        }
                    });
                    certAddress.val(address);

                }else {
                    layer.msg("请输入正确的身份证号！")
                }

            });
        });
        //监听保存
        form.on('submit(submit)', function (data) {
            layer.msg(1);

            var departmentVal = data.field.department === undefined || data.field.department === null || data.field.department === "",
                xzqhVal = data.field.xzqh === undefined || data.field.xzqh === null || data.field.xzqh === "";
            if (departmentVal && xzqhVal) {
                layer.msg("请选择所在辖区或推荐部门", {icon: 2});
                return false;
            }
            if (!departmentVal && !xzqhVal) {
                layer.msg("所在辖区或推荐部门只能选择一项", {icon: 2});
                return false;
            }
            if (data.field.id === undefined || data.field.id === null || data.field.id === "") {
                CoreUtil.sendPost("/vaccination/add", data.field, function (res) {
                    console.log(res);
                    layer.msg("保存成功");
                    clearForm();
                });
            } else {
                CoreUtil.sendPut("/vaccination/update", data.field, function (res) {
                    layer.msg("更新成功");
                    clearForm();
                });
            }

            return false;
        });
        form.on('radio(erweima)', function (data) {
            console.log(data.value);
            $("#departmentId").val("");
            document.getElementById("township").value = data.value + "000";
            layui.form.render("select");
        })
        form.on('select(department)', function (data) {
            console.log(data.value);
            $(".xzqhClass").each(function (index, el) {
                el.checked = false;
            })
            document.getElementById("township").value = data.value + "000";
            form.render('radio');
        });
        //自定义验证规则
        form.verify({
            zcReq: function (value, item) {
                var $ = layui.$;
                var verifyName = $(item).attr('name')
                    , verifyType = $(item).attr('type')
                    , formElem = $(item).parents('.layui-form')//获取当前所在的form元素，如果存在的话
                    , verifyElem = formElem.find('input[name=' + verifyName + ']')//获取需要校验的元素
                    , isTrue = verifyElem.is(':checked')//是否命中校验
                    , focusElem = verifyElem.next().find('i.layui-icon');//焦点元素
                if (!isTrue || !value) {
                    //定位焦点
                    focusElem.css(verifyType == 'radio' ? {"color": "#FF5722"} : {"border-color": "#FF5722"});
                    //对非输入框设置焦点
                    focusElem.first().attr("tabIndex", "1").css("outline", "0").blur(function () {
                        focusElem.css(verifyType == 'radio' ? {"color": ""} : {"border-color": ""});
                    }).focus();
                    return '请选择疫苗针次';
                }
            }
        });
    });
    $(function () {
        CoreUtil.sendGet("/sys/user", null, function (res) {
            if (res.data != null) {
                $(".layui-container input[name=registrant]").val(res.data.username);
                form.render(); //更新全部
            }
        });
    })
</script>
<script type="text/javascript">

    //创建读卡控件
    var CertCtl = new IDCertCtl();

    //身份证读卡控件创建
    function IDCertCtl() {
        //创建用于与服务交换数据的对象
        this.xhr = createXmlHttp();
        this.type = "CertCtl";
        this.height = 0;
        this.width = 0;
        //连接
        this.connect = CertCtl_connect;
        //断开
        this.disconnect = CertCtl_disconnect;
        //获取状态
        this.getStatus = CertCtl_getStatus;
        //读卡
        this.readCert = CertCtl_readCert;
        //读IC卡序列号
        this.readICCardSN = CertCtl_readICCardSN;
        //读身份证物理卡号
        this.readIDCardSN = CertCtl_readIDCardSN;
    }

    //创建XMLHttpRequest 对象，用于在后台与服务器交换数据
    function createXmlHttp() {
        var xmlHttp = null;
        //根据window.XMLHttpRequest对象是否存在使用不同的创建方式
        if (window.XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest();                  //FireFox、Opera等浏览器支持的创建方式
        } else {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");//IE浏览器支持的创建方式
        }
        return xmlHttp;
    }

    //连接方法
    function CertCtl_connect() {
        var result = "";
        //创建请求 第一个参数是代表以post方式发送；第二个是请求端口和地址；第三个表示是否异步
        CertCtl.xhr.open("POST", "http://127.0.0.1:18889/api/connect", false);
        //发送请求
        try {
            CertCtl.xhr.send();
        } catch (e) {
        }
        //返回值readyState   0: 请求未初始化
        //				    1: 服务器连接已建立
        //				    2：请求已接收
        //				    3: 请求处理中
        //				    4: 请求已完成，且响应已就绪
        //返回值status      200: "OK"
        //					404: 未找到页面
        //当返回值readyState为4且status为200时,为查询成功
        if (CertCtl.xhr.readyState == 4 && CertCtl.xhr.status == 200) {
            result = CertCtl.xhr.responseText;
            CertCtl.xhr.readyState = 1;
        }
        return result;
    }

    //断开方法
    function CertCtl_disconnect() {
        var result = "";
        //创建请求 第一个参数是代表以post方式发送；第二个是请求端口和地址；第三个表示是否异步
        CertCtl.xhr.open("POST", "http://127.0.0.1:18889/api/disconnect", false);
        //发送请求
        try {
            CertCtl.xhr.send();
        } catch (e) {
        }
        if (CertCtl.xhr.readyState == 4 && CertCtl.xhr.status == 200) {
            result = CertCtl.xhr.responseText;
            CertCtl.xhr.readyState = 1;
        }
        return result;
    }

    //获取状态方法
    function CertCtl_getStatus() {
        var result = "";
        //创建请求 第一个参数是代表以post方式发送；第二个是请求端口和地址；第三个表示是否异步
        CertCtl.xhr.open("POST", "http://127.0.0.1:18889/api/getStatus", false);
        //发送请求
        try {
            CertCtl.xhr.send();
        } catch (e) {
        }
        if (CertCtl.xhr.readyState == 4 && CertCtl.xhr.status == 200) {
            result = CertCtl.xhr.responseText;
            CertCtl.xhr.readyState = 1;
        }
        return result;
    }

    //执行读卡操作
    function CertCtl_readCert() {
        var result = "";
        try {
            //创建请求 第一个参数是代表以post方式发送；第二个是请求端口和地址；第三个表示是否异步
            CertCtl.xhr.open("POST", "http://127.0.0.1:18889/api/readCard", false);
            //发送请求
            CertCtl.xhr.send();
            if (CertCtl.xhr.readyState == 4 && CertCtl.xhr.status == 200) {
                result = CertCtl.xhr.responseText;
                CertCtl.xhr.readyState = 1;
            }
        } catch (e) {

        }
        return result;
    }

    //获取IC卡序列号
    function CertCtl_readICCardSN() {
        var result = "";
        //创建请求 第一个参数是代表以post方式发送；第二个是请求端口和地址；第三个表示是否异步
        CertCtl.xhr.open("POST", "http://127.0.0.1:18889/api/readICCardSN", false);
        //发送请求
        try {
            CertCtl.xhr.send();
        } catch (e) {
        }
        if (CertCtl.xhr.readyState == 4 && CertCtl.xhr.status == 200) {
            result = CertCtl.xhr.responseText;
            CertCtl.xhr.readyState = 1;
        }
        return result;
    }

    //获取身份证物理卡号
    function CertCtl_readIDCardSN() {
        var result = "";
        //创建请求 第一个参数是代表以post方式发送；第二个是请求端口和地址；第三个表示是否异步
        CertCtl.xhr.open("POST", "http://127.0.0.1:18889/api/readIDCardSN", false);
        //发送请求
        try {
            CertCtl.xhr.send();
        } catch (e) {
        }
        if (CertCtl.xhr.readyState == 4 && CertCtl.xhr.status == 200) {
            result = CertCtl.xhr.responseText;
            CertCtl.xhr.readyState = 1;
        }
        return result;
    }

    //转为Json格式
    function toJson(str) {
        //var obj = JSON.parse(str);
        //return obj;
        return eval('(' + str + ')');
    }

    //清空页面上显示的内容
    function clearForm() {
        console.log('清理表单.日志()');
        //对应控件的值全部清空
        $(".xzqhClass").each(function (index, el) {
            console.log('清理radio' + index + '::' + el);
            el.checked = false;
        })
        $(".sexClass").each(function (index, el) {
            el.checked = false;
        })
        $(".zcClass").each(function (index, el) {
            el.checked = false;
        });
        form.render('radio');
        // document.getElementById("timeElapsed").value = "";
        // document.getElementById("certType").value = "";
        // document.getElementById("timeElapsed").value = "";
        // document.getElementById("venderId").value = "";
        // document.getElementById("signature").value = "";
        document.getElementById("partyName").value = "";
        // document.getElementById("gender").value = "";
        // document.getElementById("nation").value = "";
        document.getElementById("bornDay").value = "";
        document.getElementById("certAddress").value = "";
        document.getElementById("certNumber").value = "";
        // document.getElementById("certOrg").value = "";
        // document.getElementById("effDate").value = "";
        // document.getElementById("expDate").value = "";
        // document.getElementById("result").value = "";
        document.getElementById("HeadPic").src = "";
        document.getElementById("phone").value = "";
        // document.getElementById("PhotoDisplay").src = "";
        $("#departmentId").val("");
        form.render("select");
    }

    //连接方法
    function connect() {
        //清空页面
        clearForm();

        try {
            //调用对应的连接方法,并赋值给result
            var result = CertCtl.connect();
            //如果result为空,代表读卡插件未启动
            if (result == "") {
                layer.msg('未启动读卡插件', {icon: 5});
            } else {
                //result页面回显
                // document.getElementById("result").value = result;
                console.log(result);
            }
        } catch (e) {
        }
    }

    //断开连接方法
    function disconnect() {
        //清空页面
        clearForm();

        try {
            //调用对应的断开连接方法,并赋值给result
            var result = CertCtl.disconnect();
            //如果result为空,代表读卡插件未启动
            if (result == "") {
                layer.msg('未启动读卡插件!', {icon: 5});
            } else {
                //result页面回显
                // document.getElementById("result").value = result;
                console.log(result);
            }
        } catch (e) {
        }
    }

    //获取状态方法
    function getStatus() {
        //清空页面
        clearForm();

        try {
            //调用对应的获取状态方法,并赋值给result
            var result = CertCtl.getStatus();
            //如果result为空,代表读卡插件未启动
            if (result == "") {
                layer.msg('未启动读卡插件!', {icon: 5});
            } else {
                //result页面回显
                // document.getElementById("result").value = result;
                console.log(result);
            }
        } catch (e) {
        }
    }

    //读卡方法
    function readCert() {
        console.log('开始读卡.日志()');
        //清空页面
        // clearForm();
        //开始时间
        // var startDt = new Date();
        //调用对应的读卡方法
        var result = CertCtl.readCert();
        //如果result为空,代表读卡插件未启动
        if (result == "") {
            layer.msg('未启动读卡插件!', {icon: 5});
        } else {
            //结束时间
            var endDt = new Date();
            //读卡时间回显
            // document.getElementById("timeElapsed").value = (endDt.getTime() - startDt.getTime()) + "毫秒";
            // document.getElementById("result").value = result;
            //var resultObj = toJson(result);
            //result = result.replace("\"resultFlag\":","\"resultFlag\":\"true\"");
            //格式化result
            //var resultObj = $.parseJSON(result);//windows10上面无法解析
            var resultObj = eval('(' + result + ')');
            //resultFlag为0代表读卡成功
            if (resultObj.resultFlag == "0") {
                console.log('回显相关数据.日志()');
                //回显相关数据
                // document.getElementById("signature").value = resultObj.signature;
                // document.getElementById("venderId").value = resultObj.venderId;
                // document.getElementById("certTypecertType").value = resultObj.resultContent.certType;
                document.getElementById("partyName").value = resultObj.resultContent.partyName;
                // document.getElementById("gender").value = resultObj.resultContent.gender;
                if (resultObj.resultContent.gender == "1") {
                    $("#sex1").prop('checked', true);
                } else {
                    $("#sex2").prop('checked', true);
                }
                // document.getElementById("nation").value = resultObj.resultContent.nation;
                document.getElementById("bornDay").value = resultObj.resultContent.bornDay;
                document.getElementById("certAddress").value = resultObj.resultContent.certAddress;
                document.getElementById("certNumber").value = resultObj.resultContent.certNumber;
                // document.getElementById("certOrg").value = resultObj.resultContent.certOrg;
                // document.getElementById("effDate").value = resultObj.resultContent.effDate;
                // document.getElementById("expDate").value = resultObj.resultContent.expDate;
                document.getElementById("HeadPic").src = "data:image/jpeg;base64," + resultObj.resultContent.identityPic;
                document.getElementById("phone").value = resultObj.resultContent.identityPic;
                // document.getElementById("PhotoDisplay").src = "data:image/jpeg;base64," + resultObj.resultContent.identityPrintPic;
                form.render('radio');
                var identity = document.getElementById("certNumber").value;
                if( identity != ""){
                    var exportParams = {
                        identity : identity
                    };
                    CoreUtil.sendPost("/vaccination/pinfobyidcard", exportParams, function (res) {
                        if(res.data.length>0){

                            var radioxzqh = $(".xzqhClass");
                            var departmentId =  $("#departmentId option");
                            var radiozc = $(".zcClass");
                            var radiosex = $(".sexClass");
                            var partyName = $("#partyName");
                            var sex1 =  $("#sex1");
                            var sex2 =  $("#sex2");
                            var bornday = $("#bornDay");
                            var certAddress = $("#certAddress");

                            var xzqh = res.data[0]["xzqh"];
                            var township = res.data[0]["township"];
                            var stitches = res.data[0]["stitches"];
                            var name = res.data[0]["name"];
                            var sex = res.data[0]["sex"];
                            var birthday = res.data[0]["birthday"];
                            var address = res.data[0]["address"];


                            radioxzqh.each(function (index, el) {
                                if(xzqh==radioxzqh[index].value){
                                    console.log(xzqh+"=="+radioxzqh[index].value);
                                    $(':radio[name="xzqh"]').eq(index).prop("checked",true);
                                    form.render('radio');
                                    document.getElementById("township").value = township;
                                }
                            });
                            $("#departmentId").val(xzqh);
                            layui.form.render("select");
                            radiozc.each(function (index, el) {
                                if(stitches==radiozc[index].id){
                                    radiozc[index+1].checked = true;
                                    form.render('radio');
                                }
                            });
                            // partyName.val(name);
                            // var time1 = new Date(birthday);
                            // time1.setTime(time1.getTime());
                            // var time1 = birthday.substring(0,4)+birthday.substring(5,7)+birthday.substring(8,10);
                            // bornday.val( time1);
                            // radiosex.each(function (index, el) {
                            //     if(sex==radiosex[index].value){
                            //         radiosex[index].checked = true;
                            //         form.render('radio');
                            //     }
                            // });
                            // certAddress.val(address);

                        }

                    });
                }

            } else if (resultObj.resultFlag == "-1") {
                if (resultObj.errorMsg == "端口打开失败") {
                    layer.msg('读卡器未连接!', {icon: 5});
                } else {
                    layer.msg(resultObj.errorMsg, {icon: 5});
                }
            } else if (resultObj.resultFlag == "-2") {
                layer.msg(resultObj.errorMsg, {icon: 5});
            }
        }
    }

    function readICCardSN() {
        //清空页面
        clearForm();

        try {
            //调用对应的获取状态方法,并赋值给result
            var result = CertCtl.readICCardSN();
            //如果result为空,代表读卡插件未启动
            if (result == "") {
                layer.msg('未启动读卡插件!', {icon: 5});
            } else {
                //result页面回显
                // document.getElementById("result").value = result;
                console.log(result);
            }
        } catch (e) {
        }
    }

    function readIDCardSN() {
        //清空页面
        clearForm();

        try {
            //调用对应的获取状态方法,并赋值给result
            var result = CertCtl.readIDCardSN();
            //如果result为空,代表读卡插件未启动
            if (result == "") {
                layer.msg('未启动读卡插件!', {icon: 5});
            } else {
                //result页面回显
                // document.getElementById("result").value = result;
                console.log(result);
            }
        } catch (e) {
        }
    }

    //返回
    function returnClear() {
        //清空页面
        console.log("返回调用");
        clearForm();
        return false;
    }

    //
    // $(document).keydown(function (event) {
    //     if (event.keyCode == 13) {
    //         readCert();
    //     }
    // });
</script>
<script>
    window.onload = function (e) {



        var code = "";
        var lastTime, nextTime;
        var lastCode, nextCode;
        document.onkeypress = function (e) {
            nextCode = e.which;
            nextTime = new Date().getTime();
            if (lastCode != null && lastTime != null && nextTime - lastTime <= 30) {
                code += String.fromCharCode(lastCode);
            } else if (lastCode != null && lastTime != null && nextTime - lastTime > 100) {
                code = "";
            }
            lastCode = nextCode;
            lastTime = nextTime;
        }

        this.onkeypress = function (e) {
            if (e.which == 13) {
                console.log("回车调用" + code);
                if (isNull(code)) {
                    console.log("未获取到值")
                    code = "";
                    return;
                }
                if (code.indexOf("ZC") != -1) {
                    var arr = code.split("ZC");
                    if (arr[0].length >= 9) {
                        $(".xzqhClass").each(function (index, el) {
                            el.checked = false;
                        });
                        $("#departmentId").val("");
                        var xzqh = code.substring(0, 9);
                        console.log("截取后的值" + xzqh);
                        $("#" + xzqh).prop('checked', true);
                        form.render('radio');
                        $("#departmentId").val(xzqh);
                        layui.form.render("select");
                        document.getElementById("township").value = code;
                    }
                    if (!isNull(arr[1])) {
                        console.log("开始处理针次" + arr[1]);
                        $(".zcClass").each(function (index, el) {
                            el.checked = false;
                        });
                        $("#" + arr[1]).prop('checked', true);
                        form.render('radio');
                    }
                    code = "";
                    return;
                } else {
                    if (code.length >= 9) {
                        $(".xzqhClass").each(function (index, el) {
                            el.checked = false;
                        });
                        $("#departmentId").val("");
                        var xzqh = code.substring(0, 9);
                        console.log("截取后的值" + xzqh);
                        $("#" + xzqh).prop('checked', true);
                        form.render('radio');
                        $("#departmentId").val(xzqh);
                        layui.form.render("select");
                        document.getElementById("township").value = code;
                        code = "";
                        return;
                    }
                }
            }
        }
    }

    function isNull(str) {
        if (str == "") return true;
        if (str == null) return true;
        var re = new RegExp("^[ ]+$");
        return re.test(str);
    }

</script>